{% extends "layout.html" %} {%block styles%}
<style>
  * {
    margin: 0;
    padding: 0;
    list-style: none;
    outline: none;
    text-decoration: none;
  }
  
  html {
    font-size: 100px;
  }
  
  .blank44 {
    margin-top: .44rem;
  }
  
  .comicItem .spCss {
    display: inline-block;
    flex-direction: column;
    width: 1.05rem;
    white-space: normal;
  }
  
  .comicItem .mineCss {
    width: 0.92rem;
    text-align: center;
  }
  
  .comicItem .mineCss .thumbnail {
    height: 1.24rem;
  }
  
  .comicItem .mineCss .thumbnail .score {
    display: none;
  }
  
  .comicItem .mineCss .title {
    color: #666;
  }
  
  .comicItem .comic-item .thumbnail {
    display: block;
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 133.33333%;
    border-radius: .03rem;
    box-sizing: border-box;
    background-size: cover;
    overflow: hidden;
    transform: rotate(0deg);
  }
  
  .comicItem .comic-item .thumbnail .check {
    position: absolute;
    right: .085rem;
    bottom: .085rem;
    width: .16rem;
    height: .16rem;
    background: url("../images/icons/selc.png") center no-repeat;
    background-size: cover;
    z-index: 49;
  }
  
  .comicItem .comic-item .thumbnail .checked {
    background: url("../images/icons/selc_hl.png") center no-repeat;
    background-size: cover;
  }
  
  .comicItem .comic-item .thumbnail img {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
  }
  
  .comicItem .comic-item .score {
    position: absolute;
    top: 0;
    right: 0;
    height: .18rem;
    line-height: .18rem;
    padding: 0 .04rem 0 .09rem;
    border-radius: .09rem 0 0 .09rem;
    background-color: rgba(0, 0, 0, 0.5);
    color: #fff;
    font-size: .11rem;
  }
  
  .comicItem .comic-item .score:before {
    font-size: .10rem;
    vertical-align: middle;
    margin-right: .03rem;
  }
  
  .comicItem .comic-item .title,
  .comicItem .comic-item .chapter,
  .comicItem .comic-item .desc {
    display: block;
    height: .20rem;
    line-height: .20rem;
  }
  
  .comicItem .comic-item .chapter {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 100%;
    padding: 0 .05rem;
    text-align: right;
    font-size: .12rem;
    color: #fff;
    background-color: rgba(0, 0, 0, 0.5);
  }
  
  .comicItem .comic-item .title {
    height: .25rem;
    padding-top: .05rem;
    color: #333;
    font-size: .14rem;
  }
  
  .comicItem .comic-item .desc {
    font-size: .11rem;
    color: #999;
  }
  
  .sort {
    padding: 0;
    margin: 0;
    overflow-x: hidden;
  }
  
  .sort a {
    color: #fff;
  }
  
  .sort .flex-center {
    display: flex;
    justify-content: center;
    align-items: center;
  }
  
  .sort .flex {
    flex: 1;
  }
  
  .sort .header {
    width: 100%;
    height: .44rem;
    background: #fc6454;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 103;
    display: flex;
  }
  
  .sort .header .orderBox {
    width: 1.2rem;
    height: 1.25rem;
    position: fixed;
    top: .48rem;
    right: .1rem;
    flex-flow: column nowrap;
    transition: 300ms all;
    transform-origin: 70% top;
    z-index: 99999;
    display:none;
  }
  
  .sort .header .orderBox .tri-up {
    display: inline-block;
    position: absolute;
    top: -.065rem;
    right: .31rem;
    content: '';
    width: 0;
    height: 0;
    border-width: .075rem;
    border-style: solid;
    border-color: #fff transparent;
    border-top: 0 none;
    z-index: 10;
  }
  
  .sort .header .orderBox .orderList {
    flex-flow: column nowrap;
    width: 100%;
    background-color: #fff;
    border-radius: .05rem;
    overflow: hidden;
    box-shadow: 0 0 0.05rem .015rem #999;
  }
  
  .sort .header .orderBox .orderList .order {
    width: 100%;
    font-size: .14rem;
    color: #333;
    border-bottom: 1px solid #eee;
  }
  
  .sort .header .orderBox .orderList .order a {
    color: #000;
    width: 100%;
    height: 100%;
    line-height: 300%;
    text-align: center;
  }
  
  .sort .header .title {
    width: 100%;
    color: #fff;
  }
  
  .sort .header .title .sortTitle {
    font-size: .18rem;
    text-align: center;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
    width: 36%;
    height: .25rem;
    line-height: .25rem;
  }
  
  .sort .header .title .back {
    font-size: .22rem;
    display: block;
    width: 10%;
    position: absolute;
    height: .25rem;
    line-height: .25rem;
    text-align: center;
    top: 50%;
    left: .05rem;
    margin-top: -.125rem;
  }
  
  .sort .header .title .sortx {
    font-size: .14rem;
    position: absolute;
    width: 15%;
    height: .25rem;
    line-height: .25rem;
    top: 50%;
    margin-top: -.125rem;
    text-align: center;
    right: .1rem;
  }
  
  .sort .container {
    overflow: hidden;
    padding-top: .1rem;
    margin-left: .7%;
    width: 100%;
  }
  
  .sort .container .comic-sort {
    width: 31%;
    float: left;
    margin: 0 .55% .2rem 1.1%;
  }
  
  .sort .container .comic-sort:nth-child(3n) {
    margin-right: 0;
  }
  
  .sort  .loading {
    color: #666;
    width: 100%;
    display: flex;
    justify-content: center;
    margin: .1rem 0;
    display:none;
    font-size:.14rem;
    text-align:center;
  }
  
  .sort .container .null {
    position: absolute;
    top: 45%;
    left: 50%;
    margin: -0.529rem 0 0 -0.4rem;
    text-align: center;
    color: #b9b9b9;
  }
  
  .sort .container .null .zymkwap {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: .8rem;
    opacity: .4;
    margin-bottom: .05rem;
  }
  
  .sort .container .null .zymkwap::before {
    width: .8rem;
    height: .8rem;
  }
  
  .sort .container .null span {
    font-size: .12rem;
  }
  .mask {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, .6);
    z-index: 102;
    display:none;
}
</style>
{%endblock%} {% block content %} {% import "test.html" as comicItem %}
<input type="hidden" value="{{data.coverpath}}" id="coverpath">
<input type="hidden" value="{{data.total_page}}" id="total_page">
<div class="sort">
  <div class="header">
    <div class="title">
      <span class="back zymkwap ift-goback"></span>
      <p class="sortTitle ellipsis">{{data.title if data.title else data.keyword}}</p>
      <div class="sortx">
        {{data.by}}<span class="zymkwap ift-you"></span>
      </div>
      <div class="orderBox flex-center">
        <div class="orderList flex-center flex">
          {%for item in order %}
          <div class="order flex-center flex">
            {% if data.title %}
            <a id="{{item.key}}" class="sortlist" href="/sort/type={{data.id}}&page=1&name={{item.value}}&by={{item.value}}&sort={{item.key}}">
							{{item.value}}
						</a> {% else %}
            <a id="{{item.key}}" class="sortlist" href="/sort/key={{data.keyword}}&page=1&by={{item.value}}&sort={{item.key}}">
							{{item.value}}
						</a> {% endif %}
          </div>
          {% endfor %}
        </div>
      </div>
    </div>
  </div>
  <div class="blank44"></div>
  <div class="container">
    {% for item in data.data %}
    <div class="comic-sort">
      {{ comicItem.field('',item,1) }}
    </div>
    {% endfor %}
  </div>
  <div class="loading">
    <span>大人，没有更多数据了～</span>
  </div>
  <div class="mask"></div>
</div>
{% endblock %} {% block script %}
<script src="../../../static/js/common/jquery.min.js"></script>
<script src="../../../static/js/common/util.js"></script>
<script>
  const api = 'http://api.zymk.cn/app_api/v3/';
  let pathname = location.pathname;
  let detailUrl = {
    getArg: function getArg(pathname) {
      let str = pathname.split('type=')[1];
      let idx = str.indexOf('&');
      return str.substring(0, idx);
    },
    whatsType: function whatsType(pathname) {
      if (pathname.indexOf('type') !== -1) {
        return 'type';
      } else {
        return 'key';
      }
    },
    getSort: function getSort(pathname) {
      let index = pathname.lastIndexOf('=');
      return pathname.substring(index + 1, pathname.length)
    }
  }
  let arg = detailUrl.getArg(pathname),
    sort = detailUrl.getSort(pathname),
    type = detailUrl.whatsType(pathname);
  let total_page = $('#total_page').val(),
   page = 1;
  let isMask = false,
   mask = $('.mask'),
   sortx = $('.sortx'),
   orderBox = $('.orderBox');
  function ajaxScroll(page, type, arg) {
    $.ajax({
      url: `${api}getsortlist/?${type}=${arg}&sort=${sort}&page=${page}`,
      dataType: 'jsonp',
      jsonp: 'callback',
      success: function(res) {
        addDom(detailData(res.data.page.comic_list));
      }
    })
  }

  function detailData(data) {
    let coverpath = $('#coverpath').val()
    data = score(rankListInit(data, coverpath));
    return data;
  }

  function addDom(data) {
    let str = '';
    $.each(data, function(i, v) {
      str += `<div class="comic-sort"><div class="comicItem"><a class="comic-item" href="/detail/${v.comic_id}"><div class="thumbnail"><div class="check" data-id="${v.comic_id}"></div><img class="item-img" src="${v.src}" data-id="${v.comic_id}"> <span class="zymkwap ift-xing score">${v.score}</span></div><span class="title ellipsis">${v.comic_name}</span> <span class="desc ellipsis">${v.comic_feature}</span></a></div></div>`
    })
    $('.container').append(str)
  }
  let documentObj = $(document)
  let win = $(window)
  win.scroll(function() {
    // console.log(documentObj.height() - win.height(), documentObj.scrollTop())
    if (documentObj.scrollTop() >= documentObj.height() - win.height()) {
      if (page < total_page) {
        ++page
        ajaxScroll(page, type, arg);
      } else if (page == total_page) {
        $('.loading').show();
        return
      }
    }
  })
  function showOrder(){
    if (isMask) {
				document.body.style.position = 'static';
				document.body.style.overflow = 'visible';
			} else {
				document.body.style.position = 'fixed'
				document.body.style.overflow = 'hidden'
			}
  }
  function showBox(){
    !isMask ? orderBox.show() : orderBox.hide();
    !isMask ? mask.show() : mask.hide();
    isMask = !isMask;
  }
  sortx.on('click',function(){
    showBox();
    showOrder();
  })
  mask.on('click',function(){
    showBox();
    showOrder();
  })
</script>
{% endblock %}